package org.example.model;

public class Bit {
    int[] primes = new int[]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
    public static void main(String[] args) {
        Bit bit = new Bit();


        System.out.println(1<<0);

        /**
         * 111
         * 001
         * 110
         *
         * 异或运算：x ^ 0 = x ， x ^ 1 = ~x
         * 与运算：x & 0 = 0 ， x & 1 = x
         */

        System.out.println(~1);

        System.out.println(5 ^ 0);
        System.out.println(~5);
        System.out.println(5 ^ 1);




        System.out.println(5 & 0);
        System.out.println(5 & 1);


        int[] nums = new int[]{3,5,3,3};
        int res = bit.singleNumber(nums);
        System.out.println(res);
    }

        public int singleNumber(int[] nums) {
            int ones = 0, twos = 0;
            for(int num : nums){
                ones = ones ^ num & ~twos;
                System.out.println("ones="+ones);
                twos = twos ^ num & ~ones;
                System.out.println("twos="+twos);
            }
            return ones;
        }



    private void test1(){
        int a = getMask(10);
        int b = getMask(128);
        System.out.println("a & b = " + (a & b));
        System.out.println("a | b = "+(a | b));
    }

    private int getMask(int num){
        int ans = 0;
        for(int i = 0; i < 10; i++){
            if(num % primes[i] == 0){
                ans += (1 << i);
            }
        }
        return ans;
    }
}
